
// 选择图片
const uniChooseImage = (count = 1) => {
	return new Promise((resolve, rejct) => {

		uni.chooseImage({
			// 从本地相册选择图片或使用相机拍照。
			count: count, //默认选择1张图片
			sizeType: ['original', 'compressed'], //original 原图，compressed 压缩图，默认二者都有
			success: res1 => {
				resolve(res1.tempFilePaths[0]);
			},
			fail: res => {
				console.log(res)
			}
		});
	});
}


//上传图片
const uniUpLoadFile = async () => {
	let promise;
	await uniChooseImage().then(filePath => {
		promise = new Promise((resolve, rejct) => {
			uni.showLoading({
				title: '上传中..'
			})
			uni.uploadFile({
				url: 'http://www.zhugezg.com/xq/xqBack/uploadPhoto',//服务器地址
				filePath: filePath,
				name: 'file',//我公司后端接口接收的参数是file(看你公司用什么参数名)
				header: {
					'Content-Type': 'multipart/form-data',
				},
				success: function (res) {
					uni.showToast({
						title: '上传成功'
					});
					uni.hideLoading();

					const data = res.data ? JSON.parse(res.data) : {};
					if (data.code == 1) {
						resolve(data.data)
					} else {}
				},
				fail: function (res) {
					uni.showToast({
						title: '上传图片失败'
					});
					uni.hideLoading();
				}
			});
		});
	})
	return promise;

}
export default uniUpLoadFile
